<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($_SESSION['status-slideshow'])) {
		echo "<p>".$_SESSION['status-slideshow']."</p>";
		unset($_SESSION['status-slideshow']);
	}
	?>
	<html><body>
	<form enctype="multipart/form-data" action="<?php echo site()."/".$param[0] ?>/slideshow-action" method="post" onsubmit="return validateSlideshow()">
		<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
		Pilih gambar file resolusi 950x225 kurang / lebih nanti di resize / crop :<br><input name="image" type="file" />
		<input type="submit" name="upload" id="upload" value="Upload" disabled="disabled" />
	</form>
	<?php
	$cfiles = 0;
	$limitedext = array("jpg","jpeg","png","gif");
	$files = scandir(asset_path()."/images/slideshow/");
	for($i = 0; $i < count($files); $i++) {
		$file = $files[$i];
		$getExt = explode('.',$file);
		$file_ext = $getExt[count($getExt)-1];
		if (in_array($file_ext,$limitedext)) {
			?>
			<p><a class="fancybox" data-fancybox-group="gallery" href="<?php echo site(); ?>/asset/images/slideshow/<?php echo $file; ?>"><?php echo $file; ?></a></p>
			<?php
			$cfiles++;
		}
	}
	?>
	<script type="text/javascript" src="<?php echo site()."/asset/jquery-1.7.2.min.js" ?>"></script>
	<script type="text/javascript" src="<?php echo site()."/asset/jquery.fancybox.js" ?>"></script>
	<script type="text/javascript">
	document.getElementById("upload").removeAttribute("disabled");
	function validateSlideshow() {
		var body = document.getElementsByTagName("body")[0];
		var form = document.getElementsByTagName("form")[0];
		var gambar = form["image"].value.split('.').pop().toLowerCase();
		var status = document.getElementsByTagName("p")[0] || document.createElement("p");
		if (gambar == "jpg" || gambar == "jpeg" || gambar == "png" || gambar == "gif") {
			body.removeChild(document.getElementsByTagName('p')[0]);
			return true;
		} else {
			if (document.getElementsByTagName('p')[0])
				status.innerHTML = "Tipe gambar hanya boleh jpg, jpeg, png, dan gif";
			body.insertBefore(status,form);
		}
		return false;
	}
	$(document).ready(function(){
		$('.fancybox').fancybox();
	});
	</script>
	</body></html>
	<?php
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>